package com.ruoyi.web.controller.config;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.entity.LawRegulationsStandard;
import com.ruoyi.system.entity.TargetManage;
import com.ruoyi.system.service.TargetManageService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 目指标管理(TargetManage)表控制层
 *
 * @author makejava
 * @since 2023-03-14 11:12:13
 */
@RestController
@RequestMapping("targetManage")
public class TargetManageController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private TargetManageService targetManageService;

    @GetMapping("/list")
    public TableDataInfo queryByPage(TargetManage targetManage) {
        startPage();
        List<TargetManage> list = targetManageService.queryAll(targetManage);
        return getDataTable(list);
    }

    /**
     * 分页查询
     *
     * @param targetManage 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @GetMapping
    public ResponseEntity<Page<TargetManage>> queryByPage(TargetManage targetManage, PageRequest pageRequest) {
        return ResponseEntity.ok(this.targetManageService.queryByPage(targetManage, pageRequest));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<TargetManage> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.targetManageService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param targetManage 实体
     * @return 新增结果
     */
    @PostMapping("add")
    public ResponseEntity<TargetManage> add(@Validated @RequestBody TargetManage targetManage) {
        return ResponseEntity.ok(this.targetManageService.insert(targetManage));
    }

    /**
     * 编辑数据
     *
     * @param targetManage 实体
     * @return 编辑结果
     */
    @PutMapping("edit")
    public ResponseEntity<TargetManage> edit(@Validated @RequestBody TargetManage targetManage) {
        return ResponseEntity.ok(this.targetManageService.update(targetManage));
    }

    /**
     * 删除数据
     *
     * @param targetManage 主键
     * @return 删除是否成功
     */
    @DeleteMapping("delete")
    public ResponseEntity<Boolean> deleteById(@Validated @RequestBody TargetManage targetManage) {
        return ResponseEntity.ok(this.targetManageService.deleteById(targetManage.getId()));
    }

}

